﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace demo.DBHelper
{
    /// <summary>
    /// 说明：DAO层仓储模式接口，业务逻辑层可以直接使用
    /// 时间：2016-5-3 14:50:20
    /// </summary>
    /// <typeparam name="T">表对象</typeparam>
    public interface IRepositoryDao<T> where T : class
    {
        /// <summary>
        /// 插入单条记录
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="entity">实体</param>
        /// <returns>主键值</returns>
        dynamic Add(T entity);

        /// <summary>
        /// 批量插入功能
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="entityList">实体迭代对象</param>
        /// <returns>是否成功</returns>
        bool Add(IEnumerable<T> entityList);

        /// <summary>
        /// 更新单条记录
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="entity">实体</param>
        /// <returns>是否成功</returns>
        bool Update(T entity);

        /// <summary>
        /// 批量修改功能
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="entityList">实体迭代对象</param>
        /// <returns>是否成功</returns>
        bool Update(IEnumerable<T> entityList);

        /// <summary>
        /// 删除
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="entity">实体</param>
        /// <returns>是否成功</returns>
        bool Delete(T entity);

        /// <summary>
        /// 根据主键批量删除
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="entityList">主键迭代对象</param>
        /// <returns>是否成功</returns>
        bool Delete(IEnumerable<T> entityList);

        /// <summary>
        /// 根据主键值删除
        /// </summary>
        /// <param name="key">主键值</param>
        /// <returns>是否成功</returns>
        bool Delete(dynamic key);

        /// <summary>
        /// 根据主键批量删除
        /// </summary>
        /// <param name="keys">主键迭代对象</param>
        /// <returns>是否成功</returns>
        bool Delete(IEnumerable<dynamic> keys);

        /// <summary>
        /// 获得所有数据
        /// </summary>
        /// <returns>可迭代泛型对象</returns>
        IEnumerable<T> GetAll();

        /// <summary>
        /// 根据主键获得模型
        /// </summary>
        /// <param name="key">主键</param>
        /// <returns>表实体对象</returns>
        T GetById(dynamic key);
    }
}
